package com.mp.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dcy.model.BootStrapTable;
import com.mp.entity.User;
import com.mp.mapper.UserMapper;
import com.mp.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.dcy.utils.lang.StringUtils;

import java.util.List;
/**
  * <p>
  *  服务实现类
  * </p>
  *
  * @author ShouSi
  * @since 2020-06-23
  */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<User> selectPage(BootStrapTable<User> bootStrapTable, User user) {
    EntityWrapper<User> entityWrapper = new EntityWrapper<User>();
    getEntityWrapper(entityWrapper,user);
    return super.selectPage(bootStrapTable.getPagePlus(),entityWrapper);
    }

    @Override
    public List<User> selectList(User user) {
        EntityWrapper<User> entityWrapper = new EntityWrapper<User>();
        getEntityWrapper(entityWrapper,user);
        return super.selectList(entityWrapper);
    }

    /**
    *  公共查询条件
    * @param entityWrapper
    * @return
    */
    public EntityWrapper<User> getEntityWrapper(EntityWrapper<User> entityWrapper,User user){
        //条件拼接
                    if (StringUtils.isNotBlank(user.getName())){
    entityWrapper.like(User.NAME,user.getName());
    }
                if (StringUtils.isNotBlank(user.getAge())){
    entityWrapper.like(User.AGE,user.getAge());
    }
                if (StringUtils.isNotBlank(user.getEmail())){
    entityWrapper.like(User.EMAIL,user.getEmail());
    }
                if (StringUtils.isNotBlank(user.getManager_id())){
    entityWrapper.like(User.MANAGER_ID,user.getManager_id());
    }
                if (StringUtils.isNotBlank(user.getCreate_time())){
    entityWrapper.like(User.CREATE_TIME,user.getCreate_time());
    }
                return entityWrapper;
    }
}